package com.xxx.rpc.sample.client;

import com.xxx.rpc.client.RpcProxy;
import com.xxx.rpc.sample.api.HelloService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class HelloClient3 {

	
	private static final Logger LOGGER = LoggerFactory.getLogger(HelloClient3.class);
			
    public static void main(String[] args) throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        RpcProxy rpcProxy = context.getBean(RpcProxy.class);

        int loopCount = 10000;


        HelloService helloService = rpcProxy.create(HelloService.class);
        int error = 0;
        long start = System.currentTimeMillis();
        for (int i = 0; i < loopCount; i++) {
	        try{
	        	String result = helloService.hello("World"+i);
	            LOGGER.debug(result);
	        }catch(Exception ex){
	        	LOGGER.error(ex.getClass().getName() + ":" + ex.getMessage());
	        	error ++;
	        }
        }
        long time = System.currentTimeMillis() - start;
        
        LOGGER.info("\n\n\nloop: " + loopCount);
        LOGGER.info("time: " + time + "ms");
        LOGGER.info("error: " + error + "次");
        LOGGER.info("tps: " + (double) loopCount * 1000 / ((double) time ));

        System.exit(0);
    }
}
